
<!DOCTYPE html>
<html lang="en-us">
<head>
  
  <meta charset="UTF-8" />
  <meta name="description" content="折腾 -- 自用树莓派内网穿透搭建GITEA" />
  <title>
    折腾日志(1) -- 自用树莓派内网穿透搭建GITEA | DenysG的个人博客
  </title>
  
  <meta name="viewport" content="width=device-width,user-scalable=no,maximum-scale=1,initial-scale=1">
  
  <link rel="canonical" href="https://48474.net/post/raspi-toss-log-01/"/>
  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
  
  <link rel="stylesheet" href="/css/sanitize.css">
  <link rel="stylesheet" href="/css/responsive.css">
  <link rel="stylesheet" href="/css/highlight_monokai.css">
  <link rel="stylesheet" href="/css/theme.css">
  <link rel="stylesheet" href="/css/custom.css">
  
  
  <link href="https://48474.net//index.xml" rel="alternate" type="application/rss+xml" title="DenysG的个人博客" />
  <link href="https://48474.net//index.xml" rel="feed" type="application/rss+xml" title="DenysG的个人博客" />

  
  

</head>



<body>
<div class="container">
  
  <header role="banner">
    <div class="row gutters">
      <div id="site-title" class="col span_6">
        <h1><a href="https://48474.net/">DenysG的个人博客</a></h1>
        <h2>我必须承认，幸运喜欢照顾勇敢的人。---- 达尔文</h2>
      </div>
      <div id="social" class="col span_6">
        <ul>
          
          
          <li><a href="https://github.com/cnphpbb/" target="_blank">GitHub</a></li>
          
        </ul>
      </div>
    </div>
  </header>


  
  <main id="single" role="main">
    <div class="article-header">
      <h1>折腾日志(1) -- 自用树莓派内网穿透搭建GITEA</h1>
      <div class="meta">
        Oct 14, 2020 &nbsp;
        
          #<a href="/tags/linux">linux</a>&nbsp;
        
          #<a href="/tags/raspberrypi">raspberrypi</a>&nbsp;
        
          #<a href="/tags/debian">debian</a>&nbsp;
        
          #<a href="/tags/solutions">solutions</a>&nbsp;
        
          #<a href="/tags/guide">guide</a>&nbsp;
        
          #<a href="/tags/raspi">RasPi</a>&nbsp;
        
      </div>
    </div>
    <article>
      <h3 id="自备树莓派4b">自备树莓派4B</h3>
<blockquote>
<p>这台自行组装的树莓派4B，主要用途: 存储，应用服务。</p>
</blockquote>
<ol>
<li>
<p>安装树莓派系统, 并且安装到树莓派到硬盘中</p>
<p>这里不多说安装树莓派的方法，可以自行搜索 <code>度娘</code> 或 <code>谷歌</code></p>
</li>
<li>
<p>我的树莓派是啥样子的？？   (最近搭建了个图床可以上图了) <strong>无图无真相</strong>。 <br>
<strong>主板</strong> 1 块： <br>
树莓派4B 8G</p>
</li>
</ol>
<p><strong>SSD硬盘</strong> 2块：<br>
一块 256G(上面红色的),<br>
另一块 512G(下面银色的)。 <br>
全部是 <code>浦科特（Plextor）</code> M8VC。</p>
<p><strong>扩展板</strong> 2块：</p>
<ul>
<li>
<p>X829 扩展板:: 一款2.5&rsquo; 双硬盘 NAS扩展板 <a href="https://item.taobao.com/item.htm?spm=a1z09.2.0.0.6d7c2e8dbVKdC6&amp;id=618003080805&amp;_u=e1n4bqb3463">树莓派4B&ndash;树莓派NAS集群 X829 扩展板</a></p>
</li>
<li>
<p>X735扩展板:: 电源管理和温控风扇扩展板 <a href="https://item.taobao.com/item.htm?spm=a1z09.2.0.0.6d7c2e8dbVKdC6&amp;id=592730621196&amp;_u=e1n4bqbbd1f">树莓派4B&ndash;X735电源管理和温控风扇扩展板</a></p>
</li>
</ul>
<p>俯视图
<img src="https://imgs.7y2.org/20201014085439.jpg" alt="我的树莓派">
右侧接口
<img src="https://imgs.7y2.org/20201014085457.jpg" alt="我的树莓派">
左侧HHD指示灯
<img src="https://imgs.7y2.org/20201014085508.jpg" alt="我的树莓派"></p>
<ol start="3">
<li>安装好docker，frpc 这2个服务应用</li>
</ol>
<blockquote>
<p>以上都安装好了，就可以部署自己的服务器啦。</p>
</blockquote>
<h3 id="开始折腾部署-giteahttpsgiteaiozh-cn">开始折腾部署 <a href="https://gitea.io/zh-cn/">Gitea</a></h3>
<blockquote>
<p>因为树莓派是ARM架构的, 所以原来保存的docker镜像都要重新下载</p>
</blockquote>
<ol>
<li>
<p>Pull docker images</p>
<blockquote>
<p><code>mysql</code> &amp; <code>percona</code> 的 <code>Docker Official Images</code> 中都没有ARM &amp; ARM64 的 image <br>
如果使用<code>mysql</code> 做数据库请选择 <code>mariadb</code></p>
</blockquote>
<p>我本来也想使用 <code>gitea + redis + mysql</code> 的. <br>
但是因为<code>mysql</code> 没有ARM64 的 image,  <br>
所以采用了  <code>gitea + redis + postgres</code></p>
<ul>
<li>docker pull gitea/gitea:1.12.5</li>
<li>docker pull redis:alpine</li>
<li>docker pull postgres:13-alpine</li>
</ul>
<p>这里我折腾了近半天, 为啥呢?</p>
<ol>
<li><code>mysql</code> &amp; <code>percona</code> 的 <code>Docker Official Images</code> 中都没有ARM &amp; ARM64 的 image</li>
<li><code>postgres</code> 的启动参数中不能像 <code>mysql</code> 那样, 直接使用 <code>environment</code> 来完成默认用户的权限, 需要分步走才能完成, 麻烦~</li>
<li>这里采用了创建好 <code>postgres</code> 容器后, 直接在数据库管理工具中创建 <code>gitea</code> 的 <code>用户，密码, 数据库</code></li>
</ol>
<h4 id="docker-run">docker run</h4>
<ol>
<li>
<p>建立一个网络</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="n">docker</span><span class="w"> </span><span class="n">network</span><span class="w"> </span><span class="k">create</span><span class="w"> </span><span class="o">-</span><span class="n">d</span><span class="w"> </span><span class="n">bridge</span><span class="w"> </span><span class="c1">--subnet=172.20.0.0/16 myGitNet
</span></span></span></code></pre></div></li>
<li>
<p>创建 <code>Redis</code> 容器</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="n">docker</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="o">-</span><span class="n">d</span><span class="w"> </span><span class="c1">--name gitea-redis \
</span></span></span><span class="line"><span class="cl"><span class="c1">--restart always \
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="o">-</span><span class="n">v</span><span class="w"> </span><span class="n">redis_data</span><span class="p">:</span><span class="o">/</span><span class="k">data</span><span class="w"> </span><span class="err">\</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="c1">--net myGitNet --ip 172.20.0.201 \
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="n">redis</span><span class="p">:</span><span class="mi">6</span><span class="o">-</span><span class="n">alpine</span><span class="w"> </span><span class="err">\</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="c1">--requirepass gitea
</span></span></span></code></pre></div></li>
<li>
<p>创建 <code>postgres</code> 容器</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="n">docker</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="o">-</span><span class="n">d</span><span class="w"> </span><span class="c1">--name gitea-pgsql \
</span></span></span><span class="line"><span class="cl"><span class="c1">--restart always \
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="o">-</span><span class="n">v</span><span class="w"> </span><span class="n">postgres_data</span><span class="p">:</span><span class="o">/</span><span class="n">var</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">postgresql</span><span class="o">/</span><span class="k">data</span><span class="w"> </span><span class="err">\</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">-</span><span class="n">e</span><span class="w"> </span><span class="n">POSTGRES_PASSWORD</span><span class="o">=</span><span class="n">hub</span><span class="o">#</span><span class="n">postgres</span><span class="w"> </span><span class="err">\</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="c1">--net myGitNet --ip 172.20.0.229 \
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="o">#</span><span class="w"> </span><span class="err">这里开放端口是要进行全程管理</span><span class="p">,</span><span class="w"> </span><span class="err">后期可以关闭哦</span><span class="p">.</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="o">-</span><span class="n">p</span><span class="w"> </span><span class="mi">5432</span><span class="p">:</span><span class="mi">5432</span><span class="w"> </span><span class="err">\</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="n">postgres</span><span class="p">:</span><span class="mi">13</span><span class="o">-</span><span class="n">alpine</span><span class="w">
</span></span></span></code></pre></div><p>使用数据库管理工具 <code>Navicat </code>,  建立<code>Postgres</code> 用户，密码, 数据库</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="c1">-- 
</span></span></span><span class="line"><span class="cl"><span class="c1">-- 创建用户、密码
</span></span></span><span class="line"><span class="cl"><span class="c1">--
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">CREATE</span><span class="w"> </span><span class="k">ROLE</span><span class="w"> </span><span class="s2">&#34;kevinGit&#34;</span><span class="w"> </span><span class="n">LOGIN</span><span class="w"> </span><span class="n">PASSWORD</span><span class="w"> </span><span class="s1">&#39;gY#0412#Pgsql&#39;</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="c1">-- 
</span></span></span><span class="line"><span class="cl"><span class="c1">-- 创建数据库
</span></span></span><span class="line"><span class="cl"><span class="c1">-- 
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">CREATE</span><span class="w"> </span><span class="k">DATABASE</span><span class="w"> </span><span class="s2">&#34;myGiteaDB&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="k">WITH</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="k">OWNER</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&#34;kevinGit&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="n">TABLESPACE</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&#34;pg_default&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="p">;</span><span class="w">
</span></span></span></code></pre></div></li>
<li>
<p>创建 <code>gitea</code> 容器</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sql" data-lang="sql"><span class="line"><span class="cl"><span class="n">docker</span><span class="w"> </span><span class="n">run</span><span class="w"> </span><span class="o">-</span><span class="n">d</span><span class="w"> </span><span class="c1">--name my-gitea \
</span></span></span><span class="line"><span class="cl"><span class="c1">--restart always -v gitea_data:/data \
</span></span></span><span class="line"><span class="cl"><span class="c1">--net myGitNet --ip 172.20.0.37 \
</span></span></span><span class="line"><span class="cl"><span class="c1"></span><span class="o">-</span><span class="n">p</span><span class="w"> </span><span class="mi">3022</span><span class="p">:</span><span class="mi">22</span><span class="w"> </span><span class="o">-</span><span class="n">p</span><span class="w"> </span><span class="mi">3000</span><span class="p">:</span><span class="mi">3000</span><span class="w"> </span><span class="err">\</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w"></span><span class="n">gitea</span><span class="o">/</span><span class="n">gitea</span><span class="p">:</span><span class="mi">1</span><span class="p">.</span><span class="mi">12</span><span class="p">.</span><span class="mi">5</span><span class="w">
</span></span></span></code></pre></div></li>
<li>
<p>配置 <code>gittea</code>,  访问 http://localhost:3000/</p>
<p>安装上面的UI界面, 进行逐步的配置.</p>
</li>
<li>
<p>修改 gitea的配置文件, 把 cache &amp; session 部分修改为 redis</p>
</li>
</ol>
<p><strong>到这里 gitea的docker部署 就完成了</strong></p>
<h3 id="部署-frphttpsgithubcomfatedierfrp">部署 <a href="https://github.com/fatedier/frp">FRP</a></h3>
<p>上面部署好的 <code>gitea</code> 在内网的呀, 怎么才能在公网上访问到呢?</p>
<p>现在使用 <code>frp</code> 来完成 内网中部署好的gitea, 进行内网穿透.</p>
<ol>
<li>
<p>在已有的云平台 或 有固定公网IP的服务器上部署好 frps服务</p>
<ul>
<li>配置文件。</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="k">[common]</span>
</span></span><span class="line"><span class="cl"><span class="na">bind_port</span> <span class="o">=</span> <span class="s">61007</span>
</span></span><span class="line"><span class="cl"><span class="na">vhost_http_port</span> <span class="o">=</span> <span class="s">8080</span>
</span></span><span class="line"><span class="cl"><span class="na">token</span> <span class="o">=</span> <span class="s">myToken</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="na">dashboard_port</span> <span class="o">=</span> <span class="s">17500</span>
</span></span><span class="line"><span class="cl"><span class="na">dashboard_user</span> <span class="o">=</span> <span class="s">kevinGunn</span>
</span></span><span class="line"><span class="cl"><span class="na">dashboard_pwd</span> <span class="o">=</span> <span class="s">kevin#0412</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="na">tcp_mux</span> <span class="o">=</span> <span class="s">true</span>
</span></span><span class="line"><span class="cl"><span class="na">max_pool_count</span> <span class="o">=</span> <span class="s">10</span>
</span></span></code></pre></div></li>
<li>
<p>在树莓派上部署 frpc 服务</p>
<ul>
<li>配置文件。</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="k">[common]</span>
</span></span><span class="line"><span class="cl"><span class="na">server_addr</span> <span class="o">=</span> <span class="s">**.**.**.**</span>
</span></span><span class="line"><span class="cl"><span class="na">server_port</span> <span class="o">=</span> <span class="s">61007</span>
</span></span><span class="line"><span class="cl"><span class="na">token</span> <span class="o">=</span> <span class="s">myToken</span>
</span></span><span class="line"><span class="cl"><span class="c1"># ...... //这里有别的配置省略了</span>
</span></span><span class="line"><span class="cl"><span class="k">[gov-gitea-web]</span>
</span></span><span class="line"><span class="cl"><span class="na">type</span> <span class="o">=</span> <span class="s">http</span>
</span></span><span class="line"><span class="cl"><span class="na">local_ip</span> <span class="o">=</span> <span class="s">127.0.0.1</span>
</span></span><span class="line"><span class="cl"><span class="na">local_port</span> <span class="o">=</span> <span class="s">3000</span>
</span></span><span class="line"><span class="cl"><span class="na">custom_domains</span> <span class="o">=</span> <span class="s">git.tp229.com</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">[gitea-ssh]</span>
</span></span><span class="line"><span class="cl"><span class="na">type</span> <span class="o">=</span> <span class="s">tcp</span>
</span></span><span class="line"><span class="cl"><span class="na">local_ip</span> <span class="o">=</span> <span class="s">127.0.0.1</span>
</span></span><span class="line"><span class="cl"><span class="na">local_port</span> <span class="o">=</span> <span class="s">3022</span>
</span></span><span class="line"><span class="cl"><span class="na">remote_port</span> <span class="o">=</span> <span class="s">3022</span>
</span></span></code></pre></div><blockquote>
<p>不能把 <code>22</code> 端口, 直接映射为原创的<code>22</code> 端口
所以就使用 <code>3022</code> 这个端口</p>
</blockquote>
</li>
<li>
<p>验证, 一切正常啦~~!!!!!!</p>
</li>
<li>
<p>我采用了<code>caddy</code> 做了proxy, 最终https访问.</p>
</li>
</ol>
<h3 id="最后放置一张截图-看下折腾到最后的成果">最后放置一张截图, 看下折腾到最后的成果.</h3>
<p><img src="https://imgs.7y2.org/20201015174822.png" alt="git.tp229.com"></p>
<h3 id="总结一下-我折腾过程遇到的坑">总结一下, 我折腾过程遇到的坑</h3>
<blockquote>
<ol>
<li>树莓派系统, 最后选择了 <strong>OPENFANS开源社区 &amp; 树莓派爱好者社区</strong> 联合出品的 <a href="https://github.com/openfans-community-offical/Debian-Pi-Aarch64">Debian-Pi-Aarch64</a>  <br>
&ldquo;最初直接使用的树莓派官方的系统在安装 docker 及后期的docker 部署上 各种各样的问题. &quot; <br>
&ldquo;还烧了一块 512GB的SSD. 还好在保,  漂亮温和的客服MM、直接就给我换了一块. 赞👍👍👍&rdquo;</li>
<li>mysql 没有 docker的ARM镜像.</li>
<li>postgres 提供的变量, 应该带 子数据库和子数据库账号&amp;子数据库账号密码的变量. 免得多次部署</li>
<li>gitea 中 cache &amp; seesion, 默认走的是内存模式, 应该在配置UI中增加此处的配置选择.</li>
<li>frp 不能 22 - 22 有点小遗憾. 我抽空看看代码为啥会这样.(或许是安全方面的考虑吧)</li>
<li>caddy2 配置上没有 caddy1 那样简单明了. 我还要看看是不是替换到v1版本. 越来越像NGINX的配置啦. 遗憾</li>
</ol>
</blockquote>
</li>
</ol>

      
      
      
    </article>
    


  </main>
  
  <nav class="pagination-single">
    
      <span class="previous">&larr; <a href="https://48474.net/post/ss-replace-netstat/" rel="prev">使用 ss 命令代替 netstat</a></span>
    
    
      <span class="next"><a href="https://48474.net/post/waht_it_socket/" rel="next">什么是SOCKET ？ Socket - TCP 篇</a> &rarr;</span>
    
  </nav>


  
  <footer role="contentinfo">
    <div style="text-align:center;">
      
      © 2020 135Get_Team. All rights reserved.
    </div>
  </footer>


</div>

<script src="/js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>



</body>
</html>

